//
//  DescriptionCell.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/15.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit

class DescriptionCell: UITableViewCell {

    fileprivate lazy var descriptionLB: UILabel = {
       let label = UILabel()
        label.textColor = UIColor.gray
        label.font = UIFont.systemFont(ofSize: 15)
        label.numberOfLines = 0
        return label
    }()
    
    fileprivate lazy var titleLB: UILabel = {
       let label = UILabel()
        label.text = "作品介绍"
        return label
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.addSubview(self.titleLB)
        self.contentView.addSubview(self.descriptionLB)
        selectionStyle = .none
        setUpSnap()
    }
    
    
    fileprivate func setUpSnap() {
        self.titleLB.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview().inset(UIEdgeInsetsMake(15, 15, 15, 15))
            make.height.equalTo(20)
        }
        
        self.descriptionLB.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleLB.snp.bottom)
            make.left.right.bottom.equalToSuperview().inset(UIEdgeInsetsMake(15, 15, 15, 15))
        }
    }
    
    var model: DetailStaticModel? {
        didSet{
            guard let model = model else {
                return
            }
            let content = "【\(model.comic?.cate_id ?? "")】\(model.comic?.description ?? "")"
            self.descriptionLB.text = content

        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //类方法
    class func height(_ model: DetailStaticModel?) -> CGFloat {
        var height: CGFloat = 50.0
        guard let model = model else {
            return height
        }
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 15)
        label.numberOfLines = 0
        let content = "【\(model.comic?.cate_id ?? "")】\(model.comic?.description ?? "")"
        label.text = content
        height += label.sizeThatFits(CGSize(width: kSCREEN_WIDTH - 30, height: CGFloat.infinity)).height
        return height
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
